package cn.icare.cms.controller;

import cn.icare.cms.ItemCatService;
import cn.icare.cms.feignclients.AreaClient;
import cn.icare.cms.model.vo.rest.RespMsgVO;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@CrossOrigin
@RestController
@RequestMapping(value = "/rest/area")
@Api(tags = "REST区域")
public class AreaController extends BaseController {
    @Autowired
    private AreaClient client;
    private final String FALL_STRING = "请求失败,服务繁忙!";

    /**
     * URL:http://{ip}:{port}/rest/itemcat?args={args}
     * method:GET
     *
     * @return
     */
    @GetMapping("/all")
    @HystrixCommand(fallbackMethod = "getAllFall") //增熔断器，以确保AreaClient的服务挂了后，这个接口不会卡死
    @ApiOperation(value = "查询所有区域，包含子级区域", notes = "查询所有区域，包含子级区域")
    public ResponseEntity<RespMsgVO> getAll() {
        //第一期只显示金华的数据
        Long parenId=980L;
        return this.client.getAreaList( "", 1, 0,parenId);
    }
    //#region fallback methods

    private ResponseEntity<RespMsgVO> getAllFall() {

        return super.getRespFail("查询区域失败，服务繁忙，请稍候再试");
    }
    //#endregion

}
